
#include <iostream>
using namespace std;
int Bits(int m, int n, int c){return ((c >> n) & ~(-2 << (m - n)));}

char* HtmlEncoder(const char* input, int len){
    char* output = new char[(len * 8) + 0];
    int r0 = 0;int state = 0;
    int pos = 0;
    for (int i = 0; i < len; i++){
        int c = (int)input[i];
        switch (state){
        case (0): {
            if ((((0x20<=c)&&(Bits(15,6,c)==0)&&(Bits(5,0,c)<=0x21))||((0x23<=c)&&(Bits(15,6,c)==0)&&(Bits(5,0,c)<=0x25))||((0x28<=c)&&(Bits(15,6,c)==0)&&(Bits(5,0,c)<=0x3B))||(c==0x3D)||((0x3F<=c)&&(Bits(15,7,c)==0)&&(Bits(6,0,c)<=0x7E))||((0xA1<=c)&&(Bits(15,8,c)==0)&&(Bits(7,0,c)<=0xAC))||((0xAE<=c)&&(Bits(15,10,c)==0)&&(Bits(9,0,c)<=0x36F)))) {
                output[pos++] = ((char)c);state = 0;
            } else {
                if ((c==0x22)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x71);output[pos++] = ((char)0x75);output[pos++] = ((char)0x6F);output[pos++] = ((char)0x74);output[pos++] = ((char)0x3B);state = 0;} else {if ((c==0x26)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x61);output[pos++] = ((char)0x6D);output[pos++] = ((char)0x70);output[pos++] = ((char)0x3B);state = 0;} else {if ((c==0x3C)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x6C);output[pos++] = ((char)0x74);output[pos++] = ((char)0x3B);state = 0;} else {if ((c==0x3E)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x67);output[pos++] = ((char)0x74);output[pos++] = ((char)0x3B);state = 0;} else {if ((0x10>c)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)((c&0xF)+((c&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)0x3B);state = 0;} else {if ((0x100>c)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)(((c>>4)&0xF)+(((c>>4)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)((c&0xF)+((c&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)0x3B);state = 0;} else {if ((0x1000>c)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)(((c>>8)&0xF)+(((c>>8)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)(((c>>4)&0xF)+(((c>>4)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)((c&0xF)+((c&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)0x3B);state = 0;} else {if (((0xD800<=c)&&(c<=0xDBFF))) {if ((Bits(9,6,c)==0xF)) {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)0x31);output[pos++] = ((char)0x30);output[pos++] = ((char)((Bits(15,2,c)&0xF)+((Bits(15,2,c)&0xF)<=9 ? 48 : 55)));r0 = Bits(1,0,c);state = 1;} else {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)(((1+Bits(15,6,c))&0xF)+(((1+Bits(15,6,c))&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)((Bits(15,2,c)&0xF)+((Bits(15,2,c)&0xF)<=9 ? 48 : 55)));r0 = Bits(1,0,c);state = 1;}} else {if ((((0xDC00<=c)&&(c<=0xDFFF))||(c==0xFFFF)||(c==0xFFFE))) {throw ("InvalidInput");} else {output[pos++] = ((char)0x26);output[pos++] = ((char)0x23);output[pos++] = ((char)0x58);output[pos++] = ((char)(((c>>12)&0xF)+(((c>>12)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)(((c>>8)&0xF)+(((c>>8)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)(((c>>4)&0xF)+(((c>>4)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)((c&0xF)+((c&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)0x3B);state = 0;}}}}}}}}}
            }
            break;}
        case (1): {
            if (((0xDC00<=c)&&(c<=0xDFFF))) {
                output[pos++] = ((char)((((Bits(13,0,r0)<<2)|Bits(9,8,c))&0xF)+((((Bits(13,0,r0)<<2)|Bits(9,8,c))&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)(((c>>4)&0xF)+(((c>>4)&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)((c&0xF)+((c&0xF)<=9 ? 48 : 55)));output[pos++] = ((char)0x3B);r0 = 0;state = 0;
            } else {
                throw ("InvalidInput");
            }
            break;}
        default: {
            throw ("HtmlEncoder");
                 }
        }
    }
    switch (state){
    case (0): {

        break;}
    case (1): {
        throw ("InvalidInput");
        break;}
    default: {
        throw ("HtmlEncoder");
             }
    }
    return output;
}
